// operation-message-model.js - A mongoose model
// 
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
module.exports = function (app) {
  const mongooseClient = app.get('mongooseClient');
  const { Schema } = mongooseClient;
  const operationMessage = new Schema({
    name: { type: String },// usually name should with org
    title: { type: String },
    description: { type: String },
    contents: [ { type: Schema.Types.Mixed } ],
    status: { type: String, enum: ['sended', 'saved', 'received']},
    to: {
      operations: [
        { 
          oid: { type: Schema.Types.ObjectId },
          filters: [{ type: Schema.Types.Mixed }], //filter to operators of operation
          data: { type: Schema.Types.Mixed }
        }
      ], // send all operation
      operators: [
        { 
          oid: { type: Schema.Types.ObjectId },
          data: { type: Schema.Types.Mixed }
        }
      ]
    },
    from: {
      operator: {
        oid: { type: Schema.Types.ObjectId },
        data: { type: Schema.Types.Mixed }
      }
    }
  }, {
    timestamps: true
  });

  return mongooseClient.model('operationMessage', operationMessage);
};
